<?php
	/*
		This class will handle all the database connections.
	*/

	class db
	{
		private $username;
		private $password;
		private $dbName;
		private $host;
		
		public function __construct() 
		{
			$this->username = username;
			$this->password = password;
			$this->dbName = dbname;
			$this->host = host;
		}
		
		public function get($fields, $condition, $table)
		{
			$conn = $this->connect();
			if(!$conn)
			{
				$this->close($conn);
				return $conn;
			}
			$sql = "SELECT ".$fields." FROM ".$table;
			if(strlen($condition) > 0)
			{
				$sql .= " WHERE ".$condition;
			}
			$result = mysql_query($sql);
			return $result;
			$this->close($conn);
		}
		
		public function put($fields, $table, $values)
		{
			$conn = $this->connect();
			if(!$conn)
			{
				$this->close($conn);
				return $conn;
			}
			$values = "'".str_replace(",","','",$values)."'";
			$sql = "INSERT INTO ".$table." (".$fields.")VALUES(".$values.")";
			echo $sql;
			$result = mysql_query($sql);
			$this->close($conn);
		}
		
		public function sql($statement)
		{
			$conn = $this->connect();
			if(!$conn)
			{
				$this->close($conn);
				return $conn;
			}
			$result = mysql_query($statement);
			$this->close($conn);
			return $result;
		}
		
		private function connect()
		{
			$conn = mysql_connect($this->host, $this->username, $this->password) or die('Error connecting to mysql');
			mysql_select_db($this->dbName);
			return $conn;
		}
		
		private function close($conn)
		{
			mysql_close($conn);
		}
	}
?>